package com.sanben.demand.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sanben.common.web.domain.Result;
import com.sanben.demand.data.dto.CommentDto;
import com.sanben.demand.data.req.CommentReq;
import com.sanben.demand.data.vo.CommentVo;
import com.sanben.demand.entity.Comment;
import com.sanben.demand.service.ICommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cyh
 * @description: 评论表 控制器
 * @date: 2020-08-11
 */
@RestController
@RequestMapping("comment")
@Api(tags = "评论表相关接口")
public class CommentController {

    @Autowired
	private ICommentService commentService;

	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "传入comment")
	public Result<IPage<CommentVo>> page(CommentReq req) {
		IPage<CommentVo> pages = commentService.page(req);
		return Result.data(pages);
	}

	@GetMapping("/{id}")
	@ApiOperation(value = "详情", notes = "传入id")
	public Result<Comment> detail(@PathVariable Integer id) {
	    Comment detail = commentService.detail(id);
		return Result.data(detail);
	}

	@PostMapping
	@ApiOperation(value = "新增", notes = "传入comment")
	public Result save(@RequestBody CommentDto dto) {
		return Result.data(commentService.save(dto));
	}

	@PutMapping
	@ApiOperation(value = "修改", notes = "传入comment")
	public Result update(@RequestBody CommentDto dto) {
		return Result.data(commentService.updateById(dto));
	}

	@DeleteMapping("/{ids}")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public Result remove(@PathVariable List<Integer> ids) {
		return Result.data(commentService.deleteLogic(ids));
	}

}
